package gold.digger;

import gold.vo.ListNode;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC817 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int numComponents(ListNode head, int[] nums) {
            Set<Integer> set = new HashSet<>();
            for (int num : nums) {
                set.add(num);
            }

            ListNode cur = head;
            int res = 0;
            boolean preExisit = false;
            while (cur != null) {
                if (!set.contains(cur.val)) {
                    if (preExisit) res++;
                    preExisit = false;
                } else {
                    if (cur.next == null) ++res;
                    preExisit = true;
                }

                cur = cur.next;
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC817 an = new LC817();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
